#pragma once
#ifndef NULL
	#define NULL 0
#endif

#include "Networking/servermodule.h"
#include "../Global References/VectorContainer.h"
#include "../Global References/Vectors.h"

enum e_PlayerPos
{
	POS,
	ROT,
	SCA
};

#include <fstream>

#ifndef ENGINE
#define ENGINE
class Engine;
#endif

class Networking
{
private:
	ServerModule* m_server;		// set to NULL if player is not the host
	ClientModule* m_net;		// in a multplayer game, m_net must always be active (even if player is host)

	bool m_bInitialized;
	int m_iProgramType;
	int m_iPort;
	int m_iClientNum;

	void removeDuplicateData(ByteBuffer* buffer, void* data);

public:
	std::ofstream outfile;


	Networking();
	int Init(int type, int listenPort, char* hostIP = NULL);
	static bool netCode(ServerModule * pServer, int const & a_clientIndex, void * a_data);
	bool netCode(ClientModule* c, Vector<task>& tasksForOtherClients);
	void Update();
	void Release();
	ByteBuffer* getServerMessages();
	int MakeServerRequest(int code, void* data, int dataSize);

	int getClientIndex() { return m_net->getIndex(); }
	bool isInitialized() { return m_bInitialized; }
	void setClientIndex(int i) { m_net->setIndex(i); }
};

struct MoveInfo
{
	short index;	// index of the entity
	bool bGravity;
	Vector3D pos;	// position of the entity
	Vector2D p;		// momentum of entity
};